import { create } from 'zustand'
import { immer } from 'zustand/middleware/immer'
import { devtools, persist, createJSONStorage } from 'zustand/middleware'

const usePriceStore = create()(
  immer(
    persist(
      devtools(
        (set) => ({
          price: 0,
          aaa: {
            bbb: {
              ccc: 0,
              ddd: 2,
              eee: 3
            },
          },
          setPrice: (price) => set(() => ({ price })),
          addPrice: (price) => set((state) => ({ price: state.price + price })),
          setBbb: () => set((state) => { state.aaa.bbb.ccc = state.aaa.bbb.ccc + 1 }
          ),
        }),
        {
          name: 'priceStore',
        }
      ),
      {
        name: 'priceStore',
        storage: createJSONStorage(() => sessionStorage),
      }
    )
  )
)

export default usePriceStore;
